﻿using System;
using System.Windows;

namespace Glorysoft.EAP.EAPClient.Common
{
    /// <summary>
    /// CMessageBox显示的按钮类型
    /// </summary>
    public enum AlarmMessageBoxButton
    {
        OK = 0,
        OKCancel = 1,
        YesNO = 2,
        YesNoCancel = 3
    }
    /// <summary>
    /// CMessageBox显示的图标类型
    /// </summary>
    public enum AlarmMessageBoxButtonImage
    {
        None = 0,
        Error = 1,
        Question = 2,
        Warning = 3
    }
    /// <summary>
    /// 消息的重点显示按钮
    /// </summary>
    public enum AlarmMessageBoxDefaultButton
    {
        None = 0,
        OK = 1,
        Cancel = 2,
        Yes = 3,
        No = 4
    }
    /// <summary>
    /// 消息框的返回值
    /// </summary>
    public enum AlarmMessageBoxResult
    {
        //用户直接关闭了消息窗口
        None = 0,
        //用户点击确定按钮
        OK = 1,
        //用户点击取消按钮
        Cancel = 2,
        //用户点击是按钮
        Yes = 3,
        //用户点击否按钮
        No = 4
    }
    public class AlarmMessageBox
    {
        /// <summary>
        /// 显示消息框
        /// </summary>
        /// <param name="cmessageBoxText">消息内容</param>
        public static AlarmMessageBoxResult Show(string cmessageBoxText)
        {
            AlarmMessageBoxWindow window = null;                          
            window = new  AlarmMessageBoxWindow();          
            window.MessageBoxText = cmessageBoxText;
            window.OKButtonVisibility = Visibility.Visible;         
            window.ShowDialog();        
            return window.Result;
        }
        /// <summary>
        /// 显示消息框
        /// </summary>
        /// <param name="cmessageBoxText">消息内容</param>
        /// <param name="caption">消息标题</param>
        public static AlarmMessageBoxResult Show(string cmessageBoxText, string caption)
        {
            AlarmMessageBoxWindow window = null;
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                window = new AlarmMessageBoxWindow();
            }));
            window.MessageBoxText = cmessageBoxText;
            window.MessageBoxTitle = caption;
            window.OKButtonVisibility = Visibility.Visible;
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                window.ShowDialog();
            }));
            return window.Result;
        }
        /// <summary>
        /// 显示消息框
        /// </summary>
        /// <param name="cmessageBoxText">消息内容</param>
        /// <param name="CMessageBoxButton">消息框按钮</param>
        public static AlarmMessageBoxResult Show(string cmessageBoxText, AlarmMessageBoxButton CMessageBoxButton)
        {
            AlarmMessageBoxWindow window = null;
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                window = new AlarmMessageBoxWindow();
            }));
            window.MessageBoxText = cmessageBoxText;
            switch(CMessageBoxButton)
            {
                case AlarmMessageBoxButton.OK:
                    {
                        window.OKButtonVisibility = Visibility.Visible;
                        break;
                    }
                case AlarmMessageBoxButton.OKCancel:
                    {
                        window.OKButtonVisibility = Visibility.Visible;
                        window.CancelButtonVisibility = Visibility.Visible;
                        break;
                    }
                case AlarmMessageBoxButton.YesNO:
                    {
                        window.YesButtonVisibility = Visibility.Visible;
                        window.NoButtonVisibility = Visibility.Visible;
                        break;
                    }
                case AlarmMessageBoxButton.YesNoCancel:
                    {
                        window.YesButtonVisibility = Visibility.Visible;
                        window.NoButtonVisibility = Visibility.Visible;
                        window.CancelButtonVisibility = Visibility.Visible;
                        break;
                    }
                default:
                    {
                        window.OKButtonVisibility = Visibility.Visible;
                        break;
                    }
            }
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                window.ShowDialog();
            }));
            return window.Result;
        }
        /// <summary>
        /// 显示消息框
        /// </summary>
        /// <param name="cmessageBoxText">消息内容</param>
        /// <param name="caption">消息标题</param>
        /// <param name="CMessageBoxButton">消息框按钮</param>
        public static AlarmMessageBoxResult Show(string cmessageBoxText, string caption, AlarmMessageBoxButton CMessageBoxButton)
        {
            AlarmMessageBoxWindow window = null;
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                window = new AlarmMessageBoxWindow();
            }));
            window.MessageBoxText = cmessageBoxText;
            window.MessageBoxTitle = caption;
            switch (CMessageBoxButton)
            {
                case AlarmMessageBoxButton.OK:
                    {
                        window.OKButtonVisibility = Visibility.Visible;
                        break;
                    }
                case AlarmMessageBoxButton.OKCancel:
                    {
                        window.OKButtonVisibility = Visibility.Visible;
                        window.CancelButtonVisibility = Visibility.Visible;
                        break;
                    }
                case AlarmMessageBoxButton.YesNO:
                    {
                        window.YesButtonVisibility = Visibility.Visible;
                        window.NoButtonVisibility = Visibility.Visible;
                        break;
                    }
                case AlarmMessageBoxButton.YesNoCancel:
                    {
                        window.YesButtonVisibility = Visibility.Visible;
                        window.NoButtonVisibility = Visibility.Visible;
                        window.CancelButtonVisibility = Visibility.Visible;
                        break;
                    }
                default:
                    {
                        window.OKButtonVisibility = Visibility.Visible;
                        break;
                    }
            }
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                window.ShowDialog();
            }));
            return window.Result;
        }
        /// <summary>
        /// 显示消息框
        /// </summary>
        /// <param name="cmessageBoxText">消息内容</param>
        /// <param name="caption">消息标题</param>
        /// <param name="CMessageBoxButton">消息框按钮</param>
        /// <param name="CMessageBoxImage">消息框图标</param>
        /// <returns></returns>
        public static AlarmMessageBoxResult Show(string cmessageBoxText, string caption, AlarmMessageBoxButton AlarmMessageBoxButton, AlarmMessageBoxButtonImage CMessageBoxImage)
        {
            AlarmMessageBoxWindow window = null;
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                window = new AlarmMessageBoxWindow();
            }));
            window.MessageBoxText = cmessageBoxText;
            window.MessageBoxTitle = caption;
            switch (AlarmMessageBoxButton)
            {
                case AlarmMessageBoxButton.OK:
                    {
                        window.OKButtonVisibility = Visibility.Visible;
                        break;
                    }
                case AlarmMessageBoxButton.OKCancel:
                    {
                        window.OKButtonVisibility = Visibility.Visible;
                        window.CancelButtonVisibility = Visibility.Visible;
                        break;
                    }
                case AlarmMessageBoxButton.YesNO:
                    {
                        window.YesButtonVisibility = Visibility.Visible;
                        window.NoButtonVisibility = Visibility.Visible;
                        break;
                    }
                case AlarmMessageBoxButton.YesNoCancel:
                    {
                        window.YesButtonVisibility = Visibility.Visible;
                        window.NoButtonVisibility = Visibility.Visible;
                        window.CancelButtonVisibility = Visibility.Visible;
                        break;
                    }
                default:
                    {
                        window.OKButtonVisibility = Visibility.Visible;
                        break;
                    }
            }
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                window.ShowDialog();
            }));
            return window.Result;
        }
        /// <summary>
        /// 显示消息框
        /// </summary>
        /// <param name="cmessageBoxText">消息内容</param>
        /// <param name="caption">消息标题</param>
        /// <param name="CMessageBoxButton">消息框按钮</param>
        /// <param name="CMessageBoxImage">消息框图标</param>
        /// <param name="CMessageBoxDefaultButton">消息框默认按钮</param>
        /// <returns></returns>
        public static AlarmMessageBoxResult Show(string cmessageBoxText, string caption, AlarmMessageBoxButton CMessageBoxButton, AlarmMessageBoxButtonImage CMessageBoxImage, AlarmMessageBoxDefaultButton CMessageBoxDefaultButton)
        {
            AlarmMessageBoxWindow window = null;
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                window = new AlarmMessageBoxWindow();
            }));
            window.MessageBoxText = cmessageBoxText;
            window.MessageBoxTitle = caption;
            #region 按钮
            switch (CMessageBoxButton)
            {
                case AlarmMessageBoxButton.OK:
                    {
                        window.OKButtonVisibility = Visibility.Visible;
                        break;
                    }
                case AlarmMessageBoxButton.OKCancel:
                    {
                        window.OKButtonVisibility = Visibility.Visible;
                        window.CancelButtonVisibility = Visibility.Visible;
                        break;
                    }
                case AlarmMessageBoxButton.YesNO:
                    {
                        window.YesButtonVisibility = Visibility.Visible;
                        window.NoButtonVisibility = Visibility.Visible;
                        break;
                    }
                case AlarmMessageBoxButton.YesNoCancel:
                    {
                        window.YesButtonVisibility = Visibility.Visible;
                        window.NoButtonVisibility = Visibility.Visible;
                        window.CancelButtonVisibility = Visibility.Visible;
                        break;
                    }
                default:
                    {
                        window.OKButtonVisibility = Visibility.Visible;
                        break;
                    }
            }
            #endregion
            #region 默认按钮
            switch(CMessageBoxDefaultButton)
            {
                case AlarmMessageBoxDefaultButton.OK:
                    {
                        window.OKButtonStyle = ButtonStyles.NormalButtonStyle;
                        window.CancelButtonStyle = ButtonStyles.NotNormalButtonStyle;
                        window.YesButtonStyle = ButtonStyles.NotNormalButtonStyle;
                        window.NoButtonStyle = ButtonStyles.NotNormalButtonStyle;
                        break;
                    }
                case AlarmMessageBoxDefaultButton.Cancel:
                    {
                        window.OKButtonStyle = ButtonStyles.NotNormalButtonStyle;
                        window.CancelButtonStyle = ButtonStyles.NormalButtonStyle;
                        window.YesButtonStyle = ButtonStyles.NotNormalButtonStyle;
                        window.NoButtonStyle = ButtonStyles.NotNormalButtonStyle;
                        break;
                    }
                case AlarmMessageBoxDefaultButton.Yes:
                    {
                        window.OKButtonStyle = ButtonStyles.NotNormalButtonStyle;
                        window.CancelButtonStyle = ButtonStyles.NotNormalButtonStyle;
                        window.YesButtonStyle = ButtonStyles.NormalButtonStyle;
                        window.NoButtonStyle = ButtonStyles.NotNormalButtonStyle;
                        break;
                    }
                case AlarmMessageBoxDefaultButton.No:
                    {
                        window.OKButtonStyle = ButtonStyles.NotNormalButtonStyle;
                        window.CancelButtonStyle = ButtonStyles.NotNormalButtonStyle;
                        window.YesButtonStyle = ButtonStyles.NotNormalButtonStyle;
                        window.NoButtonStyle = ButtonStyles.NormalButtonStyle;
                        break;
                    }
                case AlarmMessageBoxDefaultButton.None:
                    {
                        break;
                    }
                default:
                    {
                        break;
                    }
            }
            #endregion
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                window.ShowDialog();
            }));
            return window.Result;
        }
    }
}
